package org.zjt.demo.model;

import lombok.*;
import lombok.extern.java.Log;

import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;


/**
 * Builder ： 链式编程
 */
@Builder
@ToString
@EqualsAndHashCode
@Log
public class Trade2 {

    @NonNull
    private String id;//ID

    private String name;
    private double price;//金额

    @Builder.Default //提供默认值
    private AtomicInteger count = new AtomicInteger(0);


    @Singular //集合的声明，存放元素和操作
    private Set<String> occupations;


    /**
     * Get懒加载：
     *
     *      1、将常量（final）用AtomicReference包装初始化
     *          private final java.util.concurrent.AtomicReference<java.lang.Object> cached = new java.util.concurrent.AtomicReference<java.lang.Object>();
     *
     *      2、get延迟初始化，利用双重检测线程安全初始化AtomicReference变量。
      */

   /* @Getter(lazy = true)
    private final double[] cached = expensive();

    private double[] expensive() {
        double[] result = new double[1000000];
        for (int i = 0; i < result.length; i++) {
            result[i] = Math.asin(i);
        }
        return result;
    }*/


}  